#!/usr/bin/env python
# encoding: utf-8

import urllib.request as urlReq
import json

# url = 'http://www.baidu.com'
# url = 'https://www.lagou.com/jobs/positionAjax.json'
url = 'https://kyfw.12306.cn/otn/leftTicket/query'
data = {
    'jd':'未融资',
    'px':'new',
    'city':'上海',
    'needAddtionalResult':False
}
left_train_data = {
    'leftTicketDTO.train_date':'2018-06-04',
    'leftTicketDTO.from_station':'NCG',
    'leftTicketDTO.to_station':'FCG',
    'purpose_codes':'ADULT',
}
# resp = urlReq.urlopen(url, json.dumps(data).encode('utf-8'), timeout=100)
resp = urlReq.urlopen(url, json.dumps(left_train_data).encode('utf-8'), timeout=100)
resp_content = resp.read()
print(type(resp_content))
print(resp_content)
resp_content = resp_content.decode('utf-8')
print(type(resp_content))
with open('E:/draftspace/baidu.home.html', 'w', encoding='utf-8') as file:
    file.write(resp_content)

print(resp_content)

